package project;

public class Product
{
  private int productId;
  private ProductCategory category;
  private String name;
  private double price;
  private String unit;
  private String imageName;

  public Product()
  {
    this.productId = 0;
    this.category = null;
    this.name = "";
    this.price = 0.0D;
    this.unit = "";
    this.imageName = "";
  }

  public ProductCategory getCategory()
  {
    return this.category;
  }

  public void setCategory(ProductCategory category)
  {
    this.category = category;
  }

  public String getName()
  {
    return this.name;
  }

  public void setName(String name)
  {
    this.name = name;
  }

  public double getPrice()
  {
    return this.price;
  }

  public void setPrice(double price)
  {
    this.price = price;
  }

  public int getProductId()
  {
    return this.productId;
  }

  public void setProductId(int productId)
  {
    this.productId = productId;
  }

  public String getUnit()
  {
    return this.unit;
  }

  public String getUnitSuffix()
  {
    String[] tokens = getUnit().split("/");

    if (tokens.length == 2) {
      return tokens[1];
    }
    return "";
  }

  public void setUnit(String unit)
  {
    this.unit = unit;
  }

  public String getImageName()
  {
    return this.imageName;
  }

  public void setImageName(String imageName)
  {
    this.imageName = imageName;
  }

  public String toString()
  {
    return this.productId + " - " + this.name;
  }

  public boolean equals(Object o)
  {
    if (o instanceof Product) {
      return getProductId() == ((Product)o).getProductId();
    }
    return false;
  }
}